/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Model;
import bean.NewsBean;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

/**
 *
 * @author cpn02
 */
public class NewsModel {
    public static ArrayList<NewsBean> listNews()
    {
        Connector cnn = new Connector();
        ArrayList<NewsBean> newsList = new ArrayList<NewsBean>();
        try
        {
            Statement st = cnn.connect().createStatement();
            String query = "select * from new";
            ResultSet rs = st.executeQuery(query);
            while(rs.next())
            {
                NewsBean news = new NewsBean();
                news.setContent(rs.getString("content"));
                news.setIDN(rs.getInt("IDN"));
                news.setImage(rs.getString("image"));
                newsList.add(news);
            }
        }
        catch(ClassNotFoundException ex)
        {
            ex.printStackTrace();
        }
        catch(SQLException ex)
        {
            ex.printStackTrace();
        }
        return newsList;
    }

}
